package com.cardbaobao.cardbabyclient.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.utils.ScreenUtil;

/**
 * 底部弹出导航选择
 * Created by zad
 * 2017/1/18 10:48
 */

public class NavDialog extends Dialog implements View.OnClickListener {

    public NavDialog(Context context) {
        super(context, R.style.Theme_Dialog_From_Bottom);
        setContentView(R.layout.dialog_nav);
        setCanceledOnTouchOutside(true);
        setCancelable(true);
        initViews();
        initWindow();
    }

    private void initViews() {
        findViewById(R.id.id_tv_top).setOnClickListener(this);
        findViewById(R.id.id_tv_center).setOnClickListener(this);
        findViewById(R.id.id_tv_bottom).setOnClickListener(this);
    }

    private void initWindow() {
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = ScreenUtil.getScreenWidth(getContext());//设置对话框宽度
        params.gravity = Gravity.BOTTOM;//设置window在底部显示
        window.setAttributes(params);
    }

    @Override
    public void onClick(View v) {
        dismiss();
        switch (v.getId()) {
            case R.id.id_tv_top://百度
                if (onNavMenuListener != null) onNavMenuListener.onBaiDuNavClick(v);
                break;
            case R.id.id_tv_center://高德
                if (onNavMenuListener != null) onNavMenuListener.onAutoNavClick(v);
                break;
            case R.id.id_tv_bottom://取消

                break;
        }
    }

    public void setOnNavMenuListener(OnNavMenuListener onNavMenuListener) {
        this.onNavMenuListener = onNavMenuListener;
    }

    private OnNavMenuListener onNavMenuListener;

    /**
     *  地图导航
     */
    public interface OnNavMenuListener {
        /**
         *  百度地图
         * @param v
         */
        void onBaiDuNavClick(View v);
        /**
         *  高德地图
         * @param v
         */
        void onAutoNavClick(View v);
    }
}
